﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using MySql.Data.MySqlClient;
using IPTV.dao;
using IPTV.module;
using System.Data;
using IPTV.util;

/// <summary>
///indexService 的摘要说明
/// </summary>
namespace IPTV.service
{
    public class UserService
    {
        public UserService()
        {
            
        }

        public me_tgsg_user userLogin()
        {
            string userId = HttpContext.Current.Request.Headers["UA-DeviceId"];
            if (null == userId || userId.Equals(""))
            {
                userId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
            }
            UserDao userDao = new UserDao();
            me_tgsg_user user = new me_tgsg_user();
            List<me_tgsg_user> userList = userDao.getUserByUId(userId);
            if (null == userList || userList.Count == 0)
            {
                string ip = HttpContext.Current.Request.UserHostAddress;
                user.UserId = userId;
                user.UserIp = ip;
                user.RegisterTime = DateTime.Now;
                user.Type = CommonUtil.FREE_ACCOUNT;
                user.DeleteFlag = 0;
                userDao.addUser(user);
            }
            else
            {
                user = userList[0];
            }
            return user;
        }

        public void logUserView(me_tgsg_user user,string url , string idType ,string entId , string grade ,string subject)
        {
            me_tgsg_visitrecord record = new me_tgsg_visitrecord();
            UserDao userDao = new UserDao();
            record.Url = url;
            record.IdType = idType;
            record.EntityId = entId;
            record.Grade = grade;
            record.Subject = subject;
            record.Userid = user.UserId;
            record.Userip = user.UserIp;
            userDao.addVisitRecord(record);
        }
    }


}